package com.witmed.user.repos

import com.witmed.lib_http.ResponseData
import com.witmed.lib_http.RetrofitManager
import com.witmed.lib_http.entity.UserEntity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.RequestBody
import retrofit2.http.Query

class RegisterRepository {
    val apiService by lazy{RetrofitManager.getApiService()}

    suspend fun register(username:String,password:String):ResponseData<UserEntity>{
        return withContext(Dispatchers.IO){
            apiService.register(username, password)
        }
    }

    suspend fun sendRegCode(phone:String):ResponseData<String>{
        return withContext(Dispatchers.IO){
            apiService.sendRegCode(phone)
        }
    }

    suspend fun registerCode(body:RequestBody):ResponseData<UserEntity>{
        return withContext(Dispatchers.IO){
            apiService.registerCode(body)
        }
    }

    suspend fun login(username:String,password:String):ResponseData<UserEntity>{
        return withContext(Dispatchers.IO){
            apiService.login(username, password)
        }
    }
}